import * as XLSX from 'xlsx'

self.onmessage = async (e: any) => {
  try {
    const { file, header, sheetIndex } = e.data;
    (file as File).arrayBuffer().then((arrayBuffer) => {
      const workBook = XLSX.read(arrayBuffer)
      const formatResult = XLSX.utils.sheet_to_json(workBook.Sheets[workBook.SheetNames[sheetIndex]], { header })
      self.postMessage({ type: 'Result', v: formatResult })
    })
  } catch (e) {
    self.postMessage({ type: 'Error', e })
  }
}
